/*
 * @Author: yangzonglong
 * @Date: 2020-08-05 13:51:28
 * @version: v1.0.0
 * @Descripttion: 
 * @LastEditors: yangzonglong
 * @LastEditTime: 2021-02-19 09:32:31
 * @Auditor: 
 */
import React, { memo, useCallback } from 'react';
import preDeletePrompt from './preDeletePrompt';
import { Button } from 'antd';
import { NativeButtonProps } from 'antd/es/button/button';
import { PACKAGE_NAME } from './../../app/automatic/package';
import roleAuth from './roleAuth/roleAuth';
import history from './../../app/history';

const DeleteBtn: React.FC<NativeButtonProps> = (props) => {
  const routePermitInPath = roleAuth(history.location.pathname, PACKAGE_NAME);
  const permit = routePermitInPath.delete;

  const onClick = useCallback(() => {
    preDeletePrompt(props.onClick);
  }, [props.onClick]);

  return permit ? (
    <Button
      {...props}
      onClick={onClick}
      danger>
      {props.children || '删除'}
    </Button>
  ) : null;
};

export default memo(DeleteBtn);